<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$

/**
 +------------------------------------------------------------------------------
 * Apc缓存类
 +------------------------------------------------------------------------------
 * @category   Think
 * @package  Think
 * @subpackage  Util
 * @author    liu21st <liu21st@gmail.com>
 * @version   $Id$
 +------------------------------------------------------------------------------
 */
class CacheApc extends Cache
{//类定义开始


/**
 +----------------------------------------------------------
 * 架构函数
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 */
function __construct($options='')
{
	if(!function_exists('apc_cache_info')) {
		throw_exception(L('_NOT_SUPPERT_').':Apc');
	}
	$this->expire = isset($options['expire'])?$options['expire']:C('DATA_CACHE_TIME');
	$this->type = strtoupper(substr(__CLASS__,6));
}

/**
 +----------------------------------------------------------
 * 读取缓存
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $name 缓存变量名
 +----------------------------------------------------------
 * @return mixed
 +----------------------------------------------------------
 */
function get($name)
{
	N('cache_read',1);
	return apc_fetch($name);
}

/**
 +----------------------------------------------------------
 * 写入缓存
 *
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $name 缓存变量名
 * @param mixed $value  存储数据
 +----------------------------------------------------------
 * @return boolen
 +----------------------------------------------------------
 */
function set($name, $value, $ttl = null)
{
	N('cache_write',1);
	if(isset($ttl) && is_int($ttl))
	$expire = $ttl;
	else
	$expire = $this->expire;
	return apc_store($name, $value, $expire);
}

/**
 +----------------------------------------------------------
 * 删除缓存
 *
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $name 缓存变量名
 +----------------------------------------------------------
 * @return boolen
 +----------------------------------------------------------
 */
function rm($name)
{
	return apc_delete($name);
}

/**
 +----------------------------------------------------------
 * 清除缓存
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @return boolen
 +----------------------------------------------------------
 */
function clear()
{
	return apc_clear_cache();
}

}//类定义结束
?>